package com.oa.login.biz;

import javax.annotation.Resource;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

import com.oa.login.dao.UsersMapper;
import com.oa.login.entity.Users;
import com.oa.xinxi.utils.MD5Utils;

@Service
public class UsersBiz {
	public void login(String username,String password){
		 Subject user = SecurityUtils.getSubject();
	        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
	        try {
	            user.login(token);
	        }catch (AuthenticationException e){
	            System.out.println("登录失败");
	        }
//	        user.login(token);
	}
	
	@Resource
	private UsersMapper dao;
	
	public int find(Users u){
		return dao.find(u);
	}
	
	public Users findByUser(Users u){
		u.setPassword(MD5Utils.GetMD5Code(u.getPassword()));
		return dao.findByUsers(u);
	}
	
	
	public String findById(int id){
		return dao.findById(id);
	}
	
	public void save(Users u){
		dao.insertSelective(u);
	}
	
	public void del(int id){
		dao.deleteByPrimaryKey(id);
	}
}
